-------------------------------------------------------------------------------
-- Xavante configuration file.
--
-- The configuration defines the Xavante environment
-- Commented fields are optional and assume default values
--
-- Xavante defines virtualhosts for each site running with Xavante.
-- Each virtualhost can define the handlers for specific files extensions.
-- Xavante currently offers a fileHandler and a CGILuaHandler.
--
-- Xavante configuration can be redefined on the default file structure by the
-- the use of LUA_PATH, see more details in the online documentation.
--
-- Authors: Javier Guerra and Andre Carregal
-- Copyright (c) 2004-2006 Kepler Project
---
-- $Id: config.lua,v 1.4 2007/11/08 22:47:45 carregal Exp $
------------------------------------------------------------------------------
require "xavante.filehandler"
require "xavante.cgiluahandler"
require "xavante.redirecthandler"
require "spikes.mommhandler"
--[[
mobile device support
--]]

-- Define here where Xavante HTTP documents scripts are located
local webDir = XAVANTE_WEB

local function makerules(webDir)
    return {
        { -- URI remapping example
            match = "^[^%./]*/$",
            with = xavante.redirecthandler,
            params = { "index.lp", "index.lua", "index.http" }
        },

        { -- cgiluahandler example
            match = {"momm/" },
            with = mommhandler,
        },
        
        { -- cgiluahandler example
            match = {"%.lp$", "%.lp/.*$", "%.lua$", "%.lua/.*$" },
            with = xavante.cgiluahandler.makeHandler (XAVANTE_WEB..(webDir or ""))
        },

        { -- filehandler example
            match = ".",
            with = xavante.filehandler,
            params = { baseDir = XAVANTE_WEB..(webDir or "") }
        },

    }
end

-- Displays a message in the console with the used ports
xavante.start_message(function (ports)
    local date = os.date("[%Y-%m-%d %H:%M:%S]")
    print(string.format("%s Xavante started on port(s) %s",
      date, table.concat(ports, ", ")))
  end)

xavante.HTTP{
    server = {host = "*", port = 582},
    
    defaultHost = {
    	rules = makerules(),
    },

    virtualhosts = {
        ["www.robert.com"] = {rules = makerules("robert"),}
    },
    
}
